<?php
	if($_SESSION['access']!='0') {
		header("Location: ".HTTP_SERVER.ADMIN_DIR);
		exit;
	}
	
	$msg = "";
	//loop through all contestants and update their details if necessary
	$db->Query("SELECT * FROM contestant;");
	$members = $db->getResults();
	foreach($members as $mem) {
		//update
		if($_POST['submit'.$mem[0]]=='Update') {
			$db->Query("UPDATE contestant SET name='".$_POST['edit_cont_name'.$mem[0]]."', url='".$_POST['edit_cont_url'.$mem[0]]."' WHERE id='".$mem[0]."';");
			$msg = "<span class='success'>Update Successfull.</div>";
		}
		//delete
		if($_POST['submit'.$mem[0]]=='Delete') {
			$db->Query("DELETE FROM contestant WHERE id='".$mem[0]."';");
			$db->Query("SELECT id FROM nomination WHERE contestant_id = '".$mem[0]."';");
			while($db->getRow()) {
				$db2->Query("DELETE FROM user_vote WHERE nomination_id = '".$db->access[0]."';");
				$db2->Query("DELETE FROM user_nomination WHERE nomination_id = '".$db->access[0]."';");
				$db2->Query("DELETE FROM member_vote WHERE nomination_id = '".$db->access[0]."';");
			}
			$db->Query("DELETE FROM nomination WHERE contestant_id = '".$mem[0]."';");
			$msg = "<span class='info'>Delete Successfull.</div>";
		}
		if($msg) break;
	}
	
?>